package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class CrOMng extends JFrame {

	private JPanel contentPane;
	private IorP ip;
	private Order o;
	private Rent r;
	private Product p;
	private Item i;
	private Member m;
	private PorC pork;
	private Staff st;
	private Discount dis;
	private Delivery del;
	private Search search;

	/**
	 * Create the frame.
	 */
	public CrOMng(String s) {		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 300, 230);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setTitle(getCMtitle(s));
		
		BtnNew(s);
		BtnMng(s);
		
		JButton btnBackToMainMenu = new JButton("Back ");
		btnBackToMainMenu.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MainMenu.getInstance().setVisible(true);
				dispose();
			}
		});
		btnBackToMainMenu.setBounds(150, 120, 100, 50);
		contentPane.add(btnBackToMainMenu);
	}

	public String getCMtitle(String s)
	{
		String t="";
		switch(s){
		case "o": t="Order";break;
		case "r": t="Rent";break;
		case "i": t="Item";break;
		case "p": t="Product";break;
		case "m": t="Member";break;
		case "s": t="Staff";break;
		case "dis": t="Discount";break;
		case "del": t="Delivery"; break;
		}
		return t;
	}
	
	public void BtnNew(String s)
	{
		JButton btnNew = new JButton("Create New");
		switch(s){
		case "o":
				btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					o= new Order("new"); o.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			
			break;
		case "r":
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					r= new Rent("new"); r.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "i":
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					i= new Item("new"); i.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "p":
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					p= new Product("new"); p.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "m": 
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					pork = new PorC(); pork.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "s":
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					st= new Staff("new"); st.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "dis":
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					dis= new Discount("new"); dis.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		case "del": 
			btnNew.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					del= new Delivery("new"); del.setVisible(true); dispose();
				}
			});
				btnNew.setBounds(30, 50, 100, 50);
				contentPane.add(btnNew);
			break;
		}
		}
		
	public void BtnMng(String s)
	{
		JButton btnMng = new JButton("Manage");
		switch(s){
		case "o":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("o"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);
			
			break;
		case "r":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("r"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);;
			break;
		case "i":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("i"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);
			break;
		case "p": 
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("p"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);
			break;
		
		case "m":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("m"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);
			break;
		case "s":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("s"); search.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(150, 50, 100, 50);
			contentPane.add(btnMng);
			break;
		case "dis":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("dis"); search.setVisible(true); dispose();
				}
			});
				btnMng.setBounds(150, 50, 100, 50);
				contentPane.add(btnMng);
			break;
		case "del":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					search = new Search("del"); search.setVisible(true); dispose();
				}
			});
				btnMng.setBounds(150, 50, 100, 50);
				contentPane.add(btnMng);
			break;
		}
		}
	
}

